package com.ruoyi.water.controller;

import com.ruoyi.water.service.IPressureTokenService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

@RestController
public class PressureController {

    @Resource
    private IPressureTokenService pressureTokenService;

    @GetMapping("/pressure/api/token")
    public String getDeviceList() {
        // 1. 获取可用的accessToken
        String accessToken = pressureTokenService.getAvailableAccessToken();
        return accessToken;
    }
    /**
     * 同步设备与传感器数据到数据库
     */
    @PostMapping("/pressure/api/syncDeviceSensor")
    public String syncDeviceSensor() {
        try {
            pressureTokenService.syncAllDeviceAndSensorData();
            return "同步成功";
        } catch (Exception e) {
            return "同步失败：" + e.getMessage();
        }
    }
}